layui.config({
    base: "js/"
}).use(['form', 'layer', 'jquery','laypage'], function () {
    var form = layui.form(),
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage,
        $ = layui.jquery;

		var saleMonthServer = {
			curPage: 1,//当前页码
			total: 0,//总记录数，
			pageSize: 10,//每页显示数
			kw: '',//查询数据,
		}

    //首次获取数据
    getData();

    //查询
    $(".search_btn").click(function () {
        saleMonthServer.curPage = 1;//回到第一页
				getData();
    });



    //获取数据
    function getData() {
        saleMonthServer.kw = $('.search_input').val();
        $.ajax({
            url: '/admin/userOrderList',
            type: 'POST',
            dataType: 'json',
            data: {
                'pageNum': saleMonthServer.curPage,
                'searchVal': saleMonthServer.kw
            },
            success: function (json) {
                var Data = json;
                saleMonthServer.total = Data.totalRow;//总页数
                saleMonthServer.curPage = Data.pageNumber;//当前页
                saleMonthServer.pageSize = Data.pageSize;
                renderTable(Data.list);
                renderPage();
            }
        });
    }
    //实现分页
    function renderPage() {
        laypage.render({
            elem: 'page',
            count: saleMonthServer.total,
            limit: saleMonthServer.pageSize,
            curr: saleMonthServer.curPage,
            jump: function (obj, first) {//obj包含了当前分页的所有参数
                if (!first) {
                    getData(obj.curr);
                }
            }
        });
    }
    //渲染表格
    function renderTable(data) {
        var dataHtml = '',
            currData = data;
        if (currData.length) {
            for (var i = 0; i < currData.length; i++) {
                dataHtml = '<tr>'+
                    '<td>'+currData[i].id+'</td>'+
                    '<td>'+currData[i].productName+'</td>'+
                    '<td>'+currData[i].price+'</td>'+
                    '<td>'+currData[i].totalPrice+'</td>'+
                    '<td>'+currData[i].address+'</td>'+
                    '<td>'+currData[i].create_time+'</td>'+
                    '</tr>';
            }
        } else {
            dataHtml = '<tr><td colspan="7">暂无数据</td></tr>';
        }
        $(".saleMonth_content").html(dataHtml);
    }
})
